package march.firstmarch22.march02;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class ScoreBean implements WritableComparable<ScoreBean> {
    private String course;
    private String name;
    private Double avg = 0.;

    @Override
    public String toString() {
        return
                "课程名='" + course +
                ", 学生姓名='" + name +
                ", 平均分=" + avg ;
    }

    public String getCourse() {
        return course;
    }

    public void setCourse(String course) {
        this.course = course;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getAvg() {
        return avg;
    }

    public void setAvg(Double avg) {
        this.avg = avg;
    }

    @Override
    public int compareTo(ScoreBean o) {
        if(this.avg>o.avg){
            return -1;
        }else{
            return 1;
        }
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(course);
        out.writeUTF(name);
        out.writeDouble(avg);

    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.course = in.readUTF();
        this.name = in.readUTF();
        this.avg = in.readDouble();
    }
}
